﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Microsoft.JCI.Dal
{
    public partial class SysRoleDal
    {
        public bool IsAdmin(Guid UserId)
        {
            string sql = @"select A.* from Jci_Sys_User A
left join Jci_Sys_UserRoleRelation b on A.UserID = B.UserID
LEFT JOIN Jci_Sys_RoleFunctionRelation C ON B.RoleID = C.RoleID
LEFT JOIN Jci_Sys_Role D ON C.RoleID = D.RoleID
WHERE A.UserID = @UserId
AND D.RoleID = '11111111-1111-1111-1111-111111111111'
";
            DbCommand dbcommand = CurrentDatabase.GetSqlStringCommand(sql);
            CurrentDatabase.AddInParameter(dbcommand, "@UserId", DbType.Guid, UserId);

            DataTable dt = CurrentDatabase.ExecuteDataSet(dbcommand).Tables[0];
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
